home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / bbs / s342q07.lha / recover1.c < prev    next >
C/C++ Source or Header  |  1994-11-15  |  3KB  |  138 lines

  1. /*
  2.  *                recover1.c
  3.  *
  4.  * Recovery program for recovering killed rooms.  This only works for room
  5.  * slots which have only been killed; if the slot has been recycled (reclaimed
  6.  * by makeRoom), a different program will be needed for recovery.
  7.  */
  8.  
  9. /*
  10.  *                history
  11.  *
  12.  * 87Oct11 HAW  V3 update.
  13.  * 85Nov16 HAW  Modified for MS-DOS libraries.
  14.  * 85Apr10 HAW  Converted to MS-DOS.
  15.  * 84Jun17 HAW  Seems to work correctly.
  16.  * 84Jun17 HAW  Created.
  17.  */
  18.  
  19. #include "ctdl.h"    /* header file  */
  20. #include "fctype.h"
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <stdlib.h>
  24. #include <math.h>
  25. #include <ctype.h>
  26. #include <time.h>
  27. #include <proto/exec.h>
  28. #include <dos/dos.h>
  29. #include <pragmas/dos_pragmas.h>
  30. #include "exec/memory.h"
  31. #include "exec/ports.h"
  32. #include "exec/exec.h"
  33.  
  34.  
  35. /*
  36.  *                contents
  37.  *
  38.  *    crashout()        irrecoverable error
  39.  *    main()            main controller for this program
  40.  *    noteRoom()        enter room into RAM index
  41.  *    openFile()        opens a .sys file
  42.  */
  43.  
  44. extern rTable *roomTab;    /* RAM index of rooms    */
  45. extern aRoom  roomBuf;    /* room buffer    */
  46. extern FILE   *roomfl;    /* file descriptor for rooms    */
  47. extern int    thisRoom;    /* room currently in roomBuf    */
  48. extern CONFIG cfg;    /* A buncha variables        */
  49.  
  50. FILE *fopen();
  51. int UtilGetch(void);
  52. int  mPrintf(char *format, ...) {return 0; }  /* stub to quiet the linker */
  53.  
  54. /*
  55.  * crashout()
  56.  *
  57.  * This handles the irrecoverable error.
  58.  */
  59. void crashout(str)
  60. char *str;
  61. {
  62.     exit(printf(str));
  63. }
  64.  
  65. /*
  66.  * main()
  67.  *
  68.  * The main controller.
  69.  */
  70. int main(void);
  71. int main()
  72. {
  73.     SYS_FILE roomFile;
  74.     int Index;
  75.     char c;
  76.     cfg.weAre = UTILITY;
  77.     printf("RECOVER1 - %s\n\nGot problems, eh?  Hang on a moment...\n",
  78.                             COPYRIGHT);
  79.     if (readSysTab(TRUE, TRUE)) {
  80.     mvToHomeDisk(&cfg.homeArea);
  81.     if (access(LOCKFILE, 0) != ERROR) {
  82.         printf("Please do not run Recover1 using Outside Commands.\n");
  83.         writeSysTab();
  84.         exit(1);
  85.     }
  86.     makeSysName(roomFile, "ctdlroom.sys", &cfg.roomArea);
  87.     openFile(roomFile, &roomfl);
  88.     initRoomBuf(&roomBuf);
  89.  
  90.     for (Index = AIDEROOM + 1;    /* First 3 ALWAYS exist */
  91.         Index < MAXROOMS; Index++) {
  92.         if (!(roomTab[Index].rtflags.INUSE) && roomTab[Index].rtname[0]) {
  93.         printf("The room named %s may be recoverable. ",
  94.                         roomTab[Index].rtname);
  95.         printf("Do you want me to try? ");
  96.     c = UtilGetch();
  97.         if (toupper(c) == 'Y') {
  98.             getRoom(Index);
  99.             roomBuf.rbflags.INUSE = TRUE;
  100.             putRoom(Index);
  101.             noteRoom();
  102.         }
  103.         putchar('\n');
  104.         }
  105.     }
  106.     printf("\n\nAll finished!  Saving... No need to reconfigure.");
  107.     writeSysTab();
  108.     }
  109.     return 0;
  110. }
  111.  
  112. /*
  113.  * noteRoom()
  114.  *
  115.  * This function will enter a room into RAM index array.
  116.  */
  117. void noteRoom()
  118. {
  119.     int   i;
  120.     MSG_NUMBER last;
  121.  
  122.     last = 0l;
  123.     for (i = 0;  i < MSGSPERRM;  i++)  {
  124.     if (roomBuf.msg[i].rbmsgNo > last) {
  125.         last = roomBuf.msg[i].rbmsgNo;
  126.     }
  127.     }
  128.     roomTab[thisRoom].rtlastMessage = last    ;
  129.     strCpy(roomTab[thisRoom].rtname, roomBuf.rbname) ;
  130.     roomTab[thisRoom].rtgen    = roomBuf.rbgen  ;
  131.     roomTab[thisRoom].rtflags.INUSE    = roomBuf.rbflags.INUSE;
  132.     roomTab[thisRoom].rtflags.PUBLIC   = roomBuf.rbflags.PUBLIC;
  133.     roomTab[thisRoom].rtflags.ISDIR    = roomBuf.rbflags.ISDIR;
  134.     roomTab[thisRoom].rtflags.PERMROOM = roomBuf.rbflags.PERMROOM;
  135.     roomTab[thisRoom].rtflags.SKIP    = roomBuf.rbflags.SKIP;
  136.     roomTab[thisRoom].rtFlIndex    = roomBuf.rbFlIndex;
  137. }
  138.